<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>返件查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'返件查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="申请单位:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择申请单位" clearable filterable
            @change="factorySelectChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="返件单位:">
          <el-select v-model="queryInfo.tofactoryid" placeholder="请选择返件单位" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="p in productfamilyList" :key="p.productfamilyname" :label="p.productfamilyname"
              :value="p.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            :fetch-suggestions="getMfgordernameAsync" :value-key="'mfgordername'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='engineno' label="发动机号:">
          <el-autocomplete v-model.trim="queryInfo.engineno" placeholder="请输入发动机号" :trigger-on-focus="false"
            :fetch-suggestions="getEngineNoAsync" :value-key="'engineno'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="排故单号:">
          <el-autocomplete v-model.trim="queryInfo.dealfaultbillname" placeholder="请输入排故单号" :trigger-on-focus="false"
            :fetch-suggestions="getDealFaultBillNameAsync" :value-key="'dealfaultbillname'" :debounce="500"
            style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="编制时间:">
          <el-date-picker v-model="queryInfo.bianzhitime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="审核时间:">
          <el-date-picker v-model="queryInfo.audittime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="确认时间:">
          <el-date-picker v-model="queryInfo.confirmtime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="返出时间:">
          <el-date-picker v-model="queryInfo.fanchutime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="接收时间:">
          <el-date-picker v-model="queryInfo.jieshoutime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="完成时间:">
          <el-date-picker v-model="queryInfo.wanchengtime" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="返回时间:">
          <el-date-picker v-model="queryInfo.fanhuitime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="领取时间:">
          <el-date-picker v-model="queryInfo.lingqutime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="提交故检时间:">
          <el-date-picker v-model="queryInfo.faultcheckdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="故检报工录入时间:">
          <el-date-picker v-model="queryInfo.faultcheckreportnodate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="修理文件录入时间:">
          <el-date-picker v-model="queryInfo.jsdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="编制人:">
          <el-input v-model.trim="queryInfo.bianzhiren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="审核人:">
          <el-input v-model.trim="queryInfo.auditemp" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="确认人:">
          <el-input v-model.trim="queryInfo.confirmemp" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="返出人:">
          <el-input v-model.trim="queryInfo.fanchuren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="接收人:">
          <el-input v-model.trim="queryInfo.jieshouren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="完成人:">
          <el-input v-model.trim="queryInfo.wanchengren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="返回人:">
          <el-input v-model.trim="queryInfo.fanhuiren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="领取人:">
          <el-input v-model.trim="queryInfo.lingquren" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="提交故检人:">
          <el-input v-model.trim="queryInfo.faultcheckemp" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="故检报告录入人:">
          <el-input v-model.trim="queryInfo.faultcheckreportnoemp" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="修理文件录入人:">
          <el-input v-model.trim="queryInfo.jsemp" clearable style="width:100px;"></el-input>
        </el-form-item>

        <el-form-item label="是否故检:">
          <el-select v-model="queryInfo.isgj" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option :key="'是'" :label="'是'" :value="'是'"></el-option>
            <el-option :key="'否'" :label="'否'" :value="'否'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="返件进展:">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable>
            <el-option :key="'待返出单位技术审核'" :label="'待返出单位技术审核'" :value="'待返出单位技术审核'"></el-option>
            <el-option :key="'待返出单位检验确认'" :label="'待返出单位检验确认'" :value="'待返出单位检验确认'"></el-option>
            <el-option :key="'待返出单位返出'" :label="'待返出单位返出'" :value="'待返出单位返出'"></el-option>
            <el-option :key="'待接收单位接收'" :label="'待接收单位接收'" :value="'待接收单位接收'"></el-option>
            <el-option :key="'待接收单位完成'" :label="'待接收单位完成'" :value="'待接收单位完成'"></el-option>
            <el-option :key="'待检验故检报告'" :label="'待检验故检报告'" :value="'待检验故检报告'"></el-option>
            <el-option :key="'待工程部修理文件'" :label="'待工程部修理文件'" :value="'待工程部修理文件'"></el-option>
            <el-option :key="'待接收单位修理'" :label="'待接收单位修理'" :value="'待接收单位修理'"></el-option>
            <el-option :key="'待接收单位返回'" :label="'待接收单位返回'" :value="'待接收单位返回'"></el-option>
            <el-option :key="'待返出单位领取'" :label="'待返出单位领取'" :value="'待返出单位领取'"></el-option>
            <el-option :key="'现场已领取'" :label="'现场已领取'" :value="'现场已领取'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排故单状态:">
          <el-select v-model="queryInfo.dbstatus" placeholder="请选择" clearable style="width: 100px;">
            <el-option :key="'在用'" :label="'在用'" :value="'0'"></el-option>
            <el-option :key="'无效'" :label="'无效'" :value="'1'"></el-option>
            <el-option :key="'作废'" :label="'作废'" :value="'2'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="排故单状态" prop="dbstatus" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.dbstatus === '在用'" type="success">{{scope.row.dbstatus}}</el-tag>
            <el-tag v-else type="info">{{scope.row.dbstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="申请单位" prop="sendfactoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="130" show-overflow-tooltip></el-table-column>
        <el-table-column label="发动机号" prop="engineno" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="排故单号" prop="dealfaultbillname" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column label="组合件号" prop="productname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次号" prop="productbatchno" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="发出数" prop="fromqty" width="60"></el-table-column>
        <el-table-column label="返件单位" prop="tofactoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="返件进展" width="140" prop="status" show-overflow-tooltip></el-table-column>
        <el-table-column label="编制人" prop="createemp" width="80"></el-table-column>
        <el-table-column label="编制时间" prop="createdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="审核人" prop="auditemp" width="80"></el-table-column>
        <el-table-column label="审核时间" prop="audittime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="确认人" prop="confirmemp" width="80"></el-table-column>
        <el-table-column label="确认时间" prop="confirmtime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="返出人" prop="fromemp" width="80"></el-table-column>
        <el-table-column label="返出时间" prop="fromtime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成时间" prop="requirefinishtime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收人" prop="recvfactoryempname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="接收时间" prop="recvfactorytime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="预计完成时间" prop="estimatedcompletedate" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="完成人" prop="finishempname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="完成时间" prop="finishtime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="返回人" prop="recvfactoryreturnempname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="返回时间" prop="recvfactoryreturntime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="领取人" prop="acceptteamname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="领取时间" prop="accepttime" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="是否故检" prop="ischeck" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="实物存放地" prop="entitystoragelocation" width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="故检报告号" prop="faultcheckreportno" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="修理文件号" prop="dealfileno" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="提交故检人" prop="tjgjemp" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="提交故检时间" prop="faultcheckdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="故检报告录入人" prop="faultcheckemp" width="80"></el-table-column>
        <el-table-column label="故检报告号录入日期" prop="faultcheckreportnodate" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="修理文件录入人" prop="jsemp" width="80"></el-table-column>
        <el-table-column label="修理文件录入时间" prop="jsdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="机型" prop="enginefamily" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="接收退回原因" prop="revrejectreason" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="完成退回原因" prop="revreturnrejectreason" width="100" show-overflow-tooltip>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { fetchSuggestion, exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getFactory, getFactoryInfo, getProductFamily } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryname: '',
          factoryid: '',// 申请单位
          tofactoryid: '',// 返件单位
          productfamilyname: '', // 机型
          mfgordername: '', // 订单号
          engineno: '',// 发动机号
          dealfaultbillname: '',// 排故单号
          bianzhitime: '',// 编制人
          bianzhiren: '',// 编制时间
          fanchuren: '',// 返出人
          fanchutime: '', // 返出时间
          jieshouren: '',// 接收人
          jieshoutime: '',// 接收时间
          wanchengren: '',// 完成人
          wanchengtime: '',// 完成时间
          fanhuiren: '',// 返回人
          fanhuitime: '',// 返回时间
          lingquren: '',// 领取人
          lingqutime: '',// 领取时间
          status: '', // 返件进展
          auditemp: '',// 审核人
          audittime: '',// 审核时间
          confirmemp: '',// 确认人
          confirmtime: '',// 确认时间
          isgj: '',// 是否故检
          faultcheckemp: '',// 提交故检人
          faultcheckdate: '',// 提交故检时间
          faultcheckreportnoemp: '',// 故检报工录入人
          faultcheckreportnodate: '',// 故检报工录入时间
          jsemp: '',// 修理文件录入人
          jsdate: '',// 修理文件录入时间
          dbstatus: '0',//排故单状态
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        factoryList: [], // 分厂列表
        productfamilyList: [],
        // 表单验证
        rules: { factoryid: [{ required: true, message: '申请单位不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询发动机号
        getEngineNoAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEngineNoAsync', name: 'engineno', value, callback })
        },
        // 查询订单号
        getMfgordernameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback })
        },
        // 查询排故单号
        getDealFaultBillNameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getDealFaultBillNameAsync', name: 'dealfaultbillname', value, callback })
        },
        // 查询数据
        async getData(currentpage) {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/DealFaultBillTransferReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/DealFaultBillTransferReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        factorySelectChange(val) {
          if (!val) {
            this.queryInfo.factoryname = '';
            return;
          }
          const filter = this.factoryList.filter(i => i.factoryid === val);
          if (filter.length > 0) {
            this.queryInfo.factoryname = filter[0].factoryname;
          }
        }
      },
      async mounted() {
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const factoryList = await getFactory();
        const { factoryname } = factoryInfo[0];

        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        if (userInfo && factoryList.some(i => i.factoryid === userInfo.factoryid)) {
          this.queryInfo.factoryname = userInfo.factoryname;
          this.queryInfo.factoryid = userInfo.factoryid;
        } else {
          this.queryInfo.factoryname = factoryname;
          this.queryInfo.factoryid = factoryid;
        }

        this.factoryList = factoryList;
        this.productfamilyList = await getProductFamily();
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>